/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = __frexpect_node_free.c                             */
/*  NOTE      =                                                    */
/*  DATE      = 2016/04/12 by jikw                                 */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"
#include "frexp_comm.h"
#include "frct_expect.h"

extern void __frexpect_node_free(Frlist_node* p_st_node);

static int __suite_init(void)
{

	return 0;
}

static int __suite_cleanup(void)
{

	return 0;
}

static void case1(void)
{
    Frlist_node *p_node = NULL;

    __frexpect_node_free(p_node);
}

static void case2(void)
{
    Frlist_node *p_node = NULL;

    p_node = (Frlist_node *)frmalloc(sizeof(Frlist_node));
    if(p_node == NULL)
        return;
    memset(p_node, 0x00, sizeof(Frlist_node));
    p_node->data = NULL;

    __frexpect_node_free(p_node);

    frfree(p_node);
}

static void case3(void)
{
    Frlist_node *p_node = NULL;
    Frexp *p_st_node = NULL;
    
    p_st_node = (Frexp *)frmalloc(sizeof(Frexp));
    if(p_st_node == NULL)
        return;
    memset(p_st_node, 0x00, sizeof(Frexp));
    p_st_node->p_master_l7_module = NULL;
    p_st_node->p_lst_hdr_param = NULL;

    p_node = frlist_node_create(p_st_node);
    
    __frexpect_node_free(p_node);
    frfree(p_node);
}

static void case4(void)
{
    Frlist_node *p_node = NULL;
    Frexp *p_st_node = NULL;
    L7_module *p_master_l7_module = NULL;
    Frlist_header *p_lst_hdr_param = NULL;
    
    p_st_node = (Frexp *)frmalloc(sizeof(Frexp));
    if(p_st_node == NULL)
        return;
    memset(p_st_node, 0x00, sizeof(Frexp));
    
    p_master_l7_module = (L7_module *)frmalloc(sizeof(L7_module));
    memset(p_master_l7_module, 0x00, sizeof(L7_module));
    p_st_node->p_master_l7_module = p_master_l7_module;
    
    p_lst_hdr_param = (Frlist_header *)frmalloc(sizeof(Frlist_header));
    memset(p_lst_hdr_param, 0x00, sizeof(Frlist_header));
    p_st_node->p_lst_hdr_param = p_lst_hdr_param;

    p_node = frlist_node_create(p_st_node);
    
    __frexpect_node_free(p_node);
    frfree(p_master_l7_module);
    frfree(p_node);
}

int add_suite__frexpect_node_free(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("framework __frexpect_node_free()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", case1) == NULL ||
        CU_add_test(pSuite, "case2", case2) == NULL ||
        CU_add_test(pSuite, "case3", case3) == NULL ||
        CU_add_test(pSuite, "case4", case4) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
